<!DOCTYPE html>
<html lang="zh-CN"  xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>课程过程化管理 </title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/bootstrap/css/bootstrap.min.css}">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/font-awesome/css/font-awesome.min.css}">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" th:href="@{/static/css/fontastic.css}">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" th:href="@{https://fonts.googleapis.com/css?family=Poppins:300,400,700}">
    <!-- theme stylesheet-->
    <link rel="stylesheet" th:href="@{/static/css/style.default.css}" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" th:href="@{/static/css/custom.css}">
    <!-- Favicon-->
    <link rel="shortcut icon" th:href="@{/static/img/favicon.ico}">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
  </head>
  <body>
    <div class="page">
      <!-- Main Navbar-->
      <header class="header">
        <nav class="navbar">
          <!-- Search Box-->
          <div class="search-box">
            <button class="dismiss"><i class="icon-close"></i></button>
            <form id="searchForm" action="#" role="search">
              <input type="search"  id="myInput" onkeyup="myFunction();" placeholder="What are you looking for...(通过id搜索)"  class="form-control">
            </form>
          </div>
          <div class="container-fluid">
            <div class="navbar-holder d-flex align-items-center justify-content-between">
              <!-- Navbar Header-->
              <div class="navbar-header">
                <!-- Navbar Brand --><a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                  <div class="brand-text d-none d-lg-inline-block"><strong>侧栏</strong></div>
                  <div class="brand-text d-none d-sm-inline-block d-lg-none"><strong>BD</strong></div></a>
                <!-- Toggle Button--><a id="toggle-btn" href="#" class="menu-btn active"><span></span><span></span><span></span></a>
              </div>
              <!-- Navbar Menu -->
              <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                <!-- Search-->
                <li class="nav-item d-flex align-items-center"><a id="search" href="#"><i class="icon-search"></i></a></li>
                <!-- Notifications-->
                <li class="nav-item dropdown"> <a id="notifications" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell-o"></i><span class="badge bg-red badge-corner">1</span></a>
                  <ul aria-labelledby="notifications" class="dropdown-menu">
                    <li><a rel="nofollow" href="#" class="dropdown-item"> 
                        <div class="notification">

                        </div></a></li>
                    <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong>view all notifications                                            </strong></a></li>
                  </ul>
                </li>
                <!-- Logout    -->
                <li class="nav-item"><a th:href="@{/logout}" class="nav-link logout"> <span class="d-none d-sm-inline">退出登录</span><i class="fa fa-sign-out"></i></a></li>
              </ul>
            </div>
          </div>
        </nav>
      </header>
      <div class="page-content d-flex align-items-stretch"> 
        <!-- Side Navbar -->
        <nav class="side-navbar">
          <!-- Sidebar Header-->
          <div class="sidebar-header d-flex align-items-center">

            <div class="avatar"><img th:src="@{/static/img/avatar-1.jpg}" alt="..." class="img-fluid rounded-circle"></div>
            <div class="title">
              <h1 class="h4" th:text="${session.Main.getId()}"></h1>
              <p>管理员编号:<p th:text="${session.loginUser}"></p></p>
            </div>
          </div>
          <!-- Sidebar Navidation Menus--><span class="heading">Main</span>
          <ul class="list-unstyled">
                    <li ><a th:href="@{/adminMain}"> </i>课程管理 </a></li>
                    <li class="active"><a th:href="@{/Admin/students}"></i>学生管理 </a></li>
                    <li><a th:href="@{/Admin/teachers}"></i>教师管理 </a></li>
                    <li><a th:href="@{/Admin/classname}"></i>班级管理 </a></li>
                    <li><a th:href="@{/}"> <i class="icon-interface-windows"></i>返回主页 </a></li>
          </ul>
        </nav>
        <div class="content-inner">
          <!-- Page Header-->
          <header class="page-header">
            <div class="container-fluid">
              <button type="button" class="btn btn-info"
                      data-toggle="modal" data-target="#addModal">添加学生</button>
              <button type="button" class="btn btn-danger" id="delCousers" onclick="delStudents();">批量删除</button>
              <button type="button" class="btn btn-info"
                      data-toggle="modal" data-target="#excelModal">excel导入学生</button>
            </div>
          </header>
          <!-- Dashboard Header Section    -->
          <br>
          <div >
            <table id="table" class="table table-hover table-bordered" border="1"align="center">
             <thead>
              <tr class="font">
                <th><input type="checkbox" name="items" onclick="checkAll(this)"> 全选</th>
                <th>学号</th><th>学生姓名</th><th>性别</th><th>班级</th><th>操作</th></tr>
             </thead>
             <tbody>
              <tr th:each="s,sState:${students}">
                <td><input type="checkbox" id="item" name="item" th:value="${s.getId()}" /></td>
                <td th:text="${s.getId()}"></td>
                <td th:text="${s.getSname()}"></td>

                <!-- 判断男女 -->
                <td th:if="${s.getSsex()==1}">男</td>
                <td th:if="${s.getSsex()==0}">女</td>

                <td th:text="${s.getClassName().getClassname()}"></td>
                <td>
                  <a th:href="@{/Admin/deleteS/{id}/{pageNum}(id=${s.getId()},pageNum=${page.pageNum})}" class="btn btn-danger">删除</a>
                  <button type="button" class="btn btn-info" data-toggle="modal" data-target="#editModal"
                          onclick="editInfo(this)" th:id="${sState.index+1}">编辑</button>
                </td>
              </tr>
             </tbody>
            </table>
          </div>
          <div style="text-align: center">
            <a href="?start=1" style="display: inline-block;">[首  页]</a>  <!-- 这是相对路径的写法。 前面没有斜线就是相对当前路径加上这个地址。 -->
            <div th:if="${page.pageNum - 1 > 0}" style="display: inline-block;">
              <a th:href="@{'?start='+${page.pageNum - 1}}" >[上一页]</a>
            </div>
            <div th:if="${page.pageNum +1 < page.pages +1}" style="display: inline-block;">
              <a th:href="@{'?start='+${page.pageNum + 1}}" >[下一页]</a>
            </div>
            <a th:href="@{'?start='+${page.pages}}" style="display: inline-block;">[末  页]</a>
          </div>
          <div align="center">
            当前页/总页数：<a th:href="@{'?start='+${page.pageNum}}" th:text="${page.pageNum}"></a>/<a th:href="@{'?start='+${page.pages}}" th:text="${page.pages}"></a>
          </div>



<!--编辑学生信息-->
          <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="myModalLabel">
                    学生信息
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <form th:action="@{/Admin/updateStu}" method="post">

                  <input type="hidden" class="form-control" id="pageNum" name="pageNum" th:value="${page.pageNum}" readonly="true">

                  <div class="modal-body">
                    <div class="form-group">
                      <label for="StuId" class="col-sm-3 control-label">学生ID</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="StuId" name="StuId" readonly="true">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="spswd" class="col-sm-3 control-label">学生密码</label>
                      <div class="col-sm-9">
                        <input type="password" class="form-control" id="spswd" name="spswd" placeholder="请输入密码">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="sname" class="col-sm-3 control-label">学生名字</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="sname" name="sname" placeholder="请输入学生名字">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="classid" class="col-sm-3 control-label">班级</label>
                      <div class="col-sm-9">
                        <select class="selectpicker" id="classid" name="classid">
                          <option th:each="cn:${classNames}" th:value="${cn.getClassid()}" th:text="${cn.getClassname()}" ></option>
                        </select>
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="man" class="col-sm-3 control-label">性别</label>
                      <div class="col-sm-9">
                        <input type="radio" name="ssex" class="sex" id="man" value="1" />&nbsp;男&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="ssex" class="sex" id="women" value="0" />&nbsp;女
                      </div>
                    </div>

                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                      提交
                    </button>
                  </div>
                </form>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>




<!--添加学生信息-->
          <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="addModalLabel">
                    学生信息
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <form th:action="@{/Admin/addStudent}" method="post">
                  <div class="modal-body">

                    <div class="form-group">
                      <label for="addspswd" class="col-sm-3 control-label">学生密码</label>
                      <div class="col-sm-9">
                        <input type="password" class="form-control" id="addspswd" name="spswd" placeholder="请输入密码（不填写，默认为123456）">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="addsname" class="col-sm-3 control-label">学生名字</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="addsname" name="sname" placeholder="请输入学生名字">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="addclassid" class="col-sm-3 control-label">班级</label>
                      <div class="col-sm-9">
                        <select class="selectpicker" id="addclassid" name="classid">
                          <option th:each="cn:${classNames}" th:value="${cn.getClassid()}" th:text="${cn.getClassname()}" ></option>
                        </select>
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="addman" class="col-sm-3 control-label">性别</label>
                      <div class="col-sm-9">
                        <input type="radio" name="ssex" class="sex" id="addman" value="1" />&nbsp;男&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="ssex" class="sex" id="addwomen" value="0" />&nbsp;女
                      </div>
                    </div>

                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                      提交
                    </button>
                  </div>
                </form>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>


          <!--excel文件上传-->
          <div class="modal fade" id="excelModal" tabindex="-1" role="dialog" aria-labelledby="excelModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="excelModalLabel">
                    上传学生信息
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <form class="form form-horizontal" id="form-article-add" enctype="multipart/form-data">
                  <div class="modal-body">

                    <div class="form-group">
                      <label>请选择你要导入的excel文件(.xlsx)：</label>
                      <div class="col-sm-9">
                        <input type="file" multiple name="file" class="input-file" id="file">
                      </div>
                      
                    </div>



                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" onclick="importExcel();" class="btn btn-primary">
                      导入数据
                    </button>
                  </div>
                </form>
              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>





          <style type="text/css">
            button  {
              background:#b5cfd2 url('css/bulecell.jpg');
            }
            tr.font {
              font-size: 20px;
            }
            table.imagetable {
              font-family: verdana,arial,sans-serif;
              font-size:11px;
              color:#333333;
              border-width: 1px;
              border-color: #999999;
              border-collapse: collapse;
            }
            table.imagetable th {
              background:#b5cfd2 url('css/bulecell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }
            table.imagetable td {
              background:#dcddc0 url('css/greycell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }

            /*上传进度*/
            #fatherDiv{
              width:100px;
              height:20px;
              border:1px solid green;
            }
            #sonDiv{
              width:0px;
              height:20px;
              background:green;
            }

          </style>

          <!-- Page Footer-->
          <footer class="main-footer">
            <div class="container-fluid">
              <div class="row">
                <div class="col-sm-6">
                  <p>成都信息工程大学 &copy; 2019</p>
                </div>
              </div>
            </div>
          </footer>
        </div>
      </div>
    </div>
    <!-- JavaScript files-->
    <script th:src="@{/static/vendor/jquery/jquery.min.js}"></script>
    <script th:src="@{/static/vendor/popper.js/umd/popper.min.js}"> </script>
    <script th:src="@{/static/vendor/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/static/vendor/jquery.cookie/jquery.cookie.js}"> </script>
    <script th:src="@{/static/vendor/chart.js/Chart.min.js}"></script>
    <script th:src="@{/static/vendor/jquery-validation/jquery.validate.min.js}"></script>
    <script th:src="@{/static/js/charts-home.js}"></script>
    <script th:src="@{/static/js/findFunction.js}"></script><!--搜索功能-->
    <!-- Main File-->
    <script th:src="@{/static/js/front.js}"></script>


    <script language='javascript' th:inline="javascript">
        // 编辑课程
        function editInfo(obj) {
            var id=$(obj).attr("id");
            var sid=document.getElementById("table").rows[id].cells[1].innerText;
            var sname = document.getElementById("table").rows[id].cells[2].innerText;
            var ssex = document.getElementById("table").rows[id].cells[3].innerText;
            var sclass = document.getElementById("table").rows[id].cells[4].innerText;
            var classname=document.getElementById("classid");

            $.each([[${students}]][id-1],function(key,value){
                if(key=="spsw") {
                    var spswd=value;
                    $('#spswd').val(spswd);
                }
            });


            $('#StuId').val(sid);
            $('#sname').val(sname);

            for (var i=0;i<classname.length;i++){
                if (classname.options[i].text==sclass){
                    classname.options[i].selected = true;
                }
            }

            if (ssex == '女') {
                document.getElementById('women').checked = true;
            } else {
                document.getElementById('man').checked = true;
            }

        }

        //全选课程
        function checkAll(c) {
            var status = c.checked;
            var oItems = document.getElementsByName('item');
            for(var i=0;i<oItems.length;i++){
                oItems[i].checked=status;
            }
        }


        //删除所有选中
        function delStudents() {
            /*<![CDATA[*/
            //判断至少写了一项
            var checkedNum = $("input[name='item']:checked").length;
            if(checkedNum==0){
                alert("请至少选择一项!");
                return false;
            }
            if(confirm("确定删除所选项目?")) {
                var checkedList = new Array();
                var delsUrl = /*[[@{/Admin/deleteSs}]]*/;//获取动作地址
                $("input[name='item']:checked").each(function () {
                    checkedList.push($(this).val());
                });
                $.ajax({
                    type: "POST",
                    url: delsUrl,
                    data: {
                        "delitems": checkedList.toString()
                    },
                    datatype: 'json',
                    success: function (data) {
                        location.reload(document.URL+"?start="+[[${page.pageNum}]]);//页面刷新
                    },
                    error: function (data) {
                        art.dialog.tips('删除失败!');
                    }
                });
            }

        }


        /*导入excel数据*/
       function  importExcel()  {
            //var clientid = $("#clientid").val();
            var FormDatas=new FormData($("#form-article-add")[0]);
            var fileName=$("#file").val();
            if(fileName == '') {
                alert("请选择文件！");
                return false;
            }
            //验证文件格式
            var fileType = (fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length)).toLowerCase();
            if (fileType != 'xlsx') {
                alert("文件格式不正确");
                return false;
            }
           var excelUrl = /*[[@{/Admin/importExcel}]]*/;//获取动作地址

           $.ajax({
                type:'post',
                url:excelUrl,
                async : false,
                cache : false,
                contentType : false,
                processData : false,
                data:FormDatas,
                success: function(data){
                    if(data == "success"){
                        alert("数据导入成功！");
                        window.location.reload();
                        return false;
                    }else if(data=="error"){
                        alert("工作表名字需要为'学生信息'");
                        return false;
                    }else {
                        alert(data);
                        return false;
                    }
                },
                error : function(data){
                    alert(data);
                }
            });
        }

        /*]]>*/
    </script>



  </body>
</html>